<!DOCTYPE html>
<html>
<head>
	<meta name="renderer" content="webkit" />
	<meta http-equiv="X-UA-COMPATIBLE" content="IE=edge,chrome=1" />
	<title>宝宝优品</title>

	<link rel="icon" type="image/x-icon" href="__STATIC__/img/bitbug_favicon.ico" />
	<link rel="stylesheet" type="text/css" href="STATIC_CSS/iconfont.css" />
	<link rel="stylesheet" type="text/css" href="__STATIC__/ext/layui/css/layui.css" />
	<link rel="stylesheet" type="text/css" href="__STATIC__/loading/msgbox.css"/>
	<link rel="stylesheet" type="text/css" href="ADMIN_CSS/common.css" />
	<script src="__STATIC__/js/jquery-3.1.1.js"></script>
	<script src="__STATIC__/ext/layui/layui.js"></script>
	<script>
		layui.use(['layer', 'upload', 'element'], function() {});
		window.ns_url = {
			baseUrl: "ROOT_URL/",
			route: ['{:request()->module()}', '{:request()->controller()}', '{:request()->action()}'],
		};
	</script>
	<script src="__STATIC__/js/common.js"></script>
	<style>
		.ns-calendar{background: url("__STATIC__/img/ns_calendar.png") no-repeat center / 16px 16px;}
	</style>
	{block name="resources"}{/block}
	<script type="text/javascript">
	</script>
</head>
<body>
{block name='body'}
<!-- logo -->
<div class="ns-logo">
	
	
</div>

<div class="layui-layout layui-layout-admin">
	{block name='head'}
	<div class="layui-header">
		<!-- 一级菜单 -->
		<ul class="layui-nav layui-layout-left">
			{php}$serond_menu = [];{/php}
			{foreach $menu as $menu_k => $menu_v}
			<li class="layui-nav-item {if $menu_v.selected} layui-this{/if}">
				<a href="{$menu_v.url}">{$menu_v.title}</a>
			</li>
			{if $menu_v.selected}
				{php}
				$serond_menu = $menu_v['child_list'];
				{/php}
			{/if}
			{/foreach}
		</ul>
		<ul class="layui-nav layui-layout-right">
			<li class="layui-nav-item">
				<a href="javascript:;">
					<div class="ns-img-box">
						<img src="ADMIN_IMG/default_headimg.png" alt="">
					</div>
					{$user_info['username']}
				</a>
				<dl class="layui-nav-child">
					<dd class="ns-reset-pass" onclick="resetPassword();">
						<a href="javascript:;">修改密码</a>
					</dd>
					<dd>
						<a onclick="clearCache()" href="javascript:;">清除缓存</a>
					</dd>
					<dd>
						<a href="{:addon_url('admin/login/logout')}" class="login-out">退出登录</a>
					</dd>
				</dl>
			</li>
		</ul>
	</div>
	{/block}

	{notempty name="$serond_menu"}
	<div class="layui-side">
		<div class="layui-side-scroll">
			<span class="ns-side-title">{$crumbs[0]['title']}</span>
			<!-- 二三级菜单-->
			<ul class="layui-nav layui-nav-tree"  lay-filter="test">
				{foreach $serond_menu as $menu_second_k => $menu_second_v}
				<li class="layui-nav-item {if $menu_second_v.selected} layui-nav-itemed {/if}{if !$menu_second_v.child_list && $menu_second_v.selected} layui-this{/if}">
					<a class="layui-menu-tips" href="{if !$menu_second_v.child_list} {$menu_second_v.url} {else/}javascript:;{/if}">{$menu_second_v.title}</a>
					{notempty name="$menu_second_v.child_list"}
					<dl class="layui-nav-child">
						{foreach $menu_second_v["child_list"] as $menu_third_k => $menu_third_v}
						<dd class="{if $menu_third_v.selected} layui-this{/if}">
							<a href="{$menu_third_v.url}">{$menu_third_v.title}</a>
						</dd>
						{/foreach}
					</dl>
					{/notempty}
				</li>
				{/foreach}
			</ul>
		</div>
	</div>
	{/notempty}

	<div class="layui-body{empty name='$serond_menu'} child_no_exit{/empty}">
		<!-- 面包屑 -->
		{block name='crumbs'}
		{if count($serond_menu) > 0}
		<div class="ns-crumbs{empty name='$serond_menu'} child_no_exit{/empty}">
		<span class="layui-breadcrumb" lay-separator="-">
			{foreach $crumbs as $crumbs_k => $crumbs_v}
			{if count($crumbs) == ($crumbs_k + 1)}
			<a href="{$crumbs_v.url}"><cite>{$crumbs_v.title}</cite></a>
			{else/}
			<a href="{$crumbs_v.url}">{$crumbs_v.title}</a>
			{/if}
			{/foreach}
		</span>
		</div>
		{/if}
		{/block}
		<div class="ns-body-content {if count($serond_menu) < 1} crumbs_no_exit{/if}">
			<div class="ns-body">
				<!-- 四级导航 -->
				{if condition="isset($forth_menu) && !empty($forth_menu)"}
				<div class="fourstage-nav layui-tab layui-tab-brief" lay-filter="edit_user_tab">
					<ul class="layui-tab-title">
						{volist name="$forth_menu" id="menu"}
						<li class="{$menu.selected == 1 ? 'layui-this' : ''}" lay-id="basic_info"><a href="{$menu.parse_url}">{$menu.title}</a></li>
						{/volist}
					</ul>
				</div>
				{/if}
				
				{block name="main"} {/block}
			</div>
			
			<!-- 版权信息 -->
			<div class="ns-footer">
				<div class="ns-footer-img">
					<a href="#"><img style="-webkit-filter: grayscale(100%);-moz-filter: grayscale(100%);-ms-filter: grayscale(100%);-o-filter: grayscale(100%);filter: grayscale(100%);filter: gray;" src="{if !empty($copyright.logo)} {:img($copyright.logo)} {else /}__STATIC__/img/copyright_logo.png{/if}" /></a>
				</div>
			</div>
		</div>
	</div>
</div>

<!-- 重置密码弹框html -->
<div class="layui-form" id="reset_pass" style="display: none;">
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="required">*</span>原密码</label>
        <div class="layui-input-block">
            <input type="password" id="old_pass" name="old_pass" required class="layui-input ns-len-mid" maxlength="18" autocomplete="off" readonly onfocus="this.removeAttribute('readonly');" onblur="this.setAttribute('readonly',true);">
            <span class="required"></span>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><span class="required">*</span>新密码</label>
        <div class="layui-input-block">
            <input type="password" id="new_pass" name="new_pass" required class="layui-input ns-len-mid" maxlength="18" autocomplete="off" readonly onfocus="this.removeAttribute('readonly');" onblur="this.setAttribute('readonly',true);">
            <span class="required"></span>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><span class="required">*</span>确认新密码</label>
        <div class="layui-input-block">
            <input type="password" id="repeat_pass" name="repeat_pass" required class="layui-input ns-len-mid" maxlength="18" autocomplete="off" readonly onfocus="this.removeAttribute('readonly');" onblur="this.setAttribute('readonly',true);">
            <span class="required"></span>
        </div>
    </div>

    <div class="ns-form-row">
        <button class="layui-btn ns-bg-color" onclick="repass()">确定</button>
        <button class="layui-btn layui-btn-primary" onclick="closePass()">返回</button>
    </div>
</div>
<script type="text/javascript">
	layui.use('element',function () {
		var element = layui.element;
		element.render('breadcrumb');
	});
	function clearCache () {
		$.ajax({
			type: 'post',
			url: ns.url("admin/Login/clearCache"),
			dataType: 'JSON',
			success: function(res) {
				layer.msg(res.message);
				location.reload();
			}
		})
	}

    /**
     * 重置密码
     */
	var index;
    function resetPassword() {
        index = layer.open({
            type:1,
            content:$('#reset_pass'),
            offset: 'auto',
            area: ['650px']
        });

		setTimeout(function() {
			$(".ns-reset-pass").removeClass('layui-this');
		}, 1000);
    }

	// $(".ns-reset-pass").on('click', function() {
	// 	$(this).removeClass('layui-this');
	// })

    var repeat_flag = false;
    function repass(){
        var old_pass = $("#old_pass").val();
        var new_pass = $("#new_pass").val();
        var repeat_pass = $("#repeat_pass").val();

        if (old_pass == '') {
            $("#old_pass").focus();
            layer.msg("原密码不能为空");
            return;
        }

        if (new_pass == '') {
            $("#new_pass").focus();
            layer.msg("密码不能为空");
            return;
        } else if ($("#new_pass").val().length < 6) {
            $("#new_pass").focus();
            layer.msg("密码不能少于6位数");
            return;
        }
        if (repeat_pass == '') {
            $("#repeat_pass").focus();
            layer.msg("密码不能为空");
            return;
        } else if ($("#repeat_pass").val().length < 6) {
            $("#repeat_pass").focus();
            layer.msg("密码不能少于6位数");
            return;
        }
        if (new_pass != repeat_pass) {
            $("#repeat_pass").focus();
            layer.msg("两次密码输入不一样，请重新输入");
            return;
        }

        if(repeat_flag)return;
        repeat_flag = true;

        $.ajax({
            type: "POST",
            dataType: 'JSON',
            url: ns.url("admin/login/modifypassword"),
            data: {"old_pass": old_pass,"new_pass": new_pass},
            success: function(res) {
                layer.msg(res.message);
                repeat_flag = false;

                if (res.code == 0) {
                    layer.close(index);
                    location.reload();
                }
            }
        });
    }

    function closePass() {
        layer.close(index);
    }
	
	layui.use('element', function() {
		var element = layui.element;
		element.init();
	});
</script>
{/block}
{block name="script"}
{/block}
</body>
</html>